﻿#region Copyright 2011 Mike Goatly
// This source is subject to the the MIT License (MIT)
// All rights reserved.
#endregion

namespace VS2010MethodIndexer
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Lifti;
    #endregion

    /// <summary>
    /// A word splitter that only considers capital letters to be parts of a word.
    /// </summary>
    internal class PascalCaseWordSplitter : IWordSplitter
    {
        #region Public Methods

        /// <inheritdoc />
        public IEnumerable<SplitWord> SplitWords(string text)
        {
            var builder = new StringBuilder();

            int index = 0;
            foreach (var character in text)
            {
                if (Char.IsUpper(character) && builder.Length > 0)
                {
                    yield return new SplitWord(builder.ToString(), index++);
                    builder.Length = 0;
                }

                builder.Append(character);
            }

            if (builder.Length > 0)
            {
                yield return new SplitWord(builder.ToString(), index);
            }
        }

        /// <inheritdoc />
        public IEnumerable<SplitWord> SplitWords(IEnumerable<string> text)
        {
            throw new NotImplementedException();
        }

        /// <inheritdoc />
        public string Normalize(string word)
        {
            // No-op in this example.
            return word;
        }

        #endregion
    }
}
